<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2019/1/12
 * Time: 21:15
 */

//同步的代码实现异步操作
//注意 协程客户端需要在 回调里面使用

$http=new  swoole_http_server('0.0.0.0',8001);
$http->on('request',function (swoole_http_request $request,swoole_http_response $response){
    $redis= new  Swoole\Coroutine\Redis();
    $redis->connect('127.0.0.1',6379);
//$redis->set('coroutine',time());
    $response->header('Content-Type:','text/plain;charset=utf-8');
    $redis_value=$redis->get($request->get['a']);
    //mysql redis 业务逻辑
    //那么整体耗时 max([mysql,redis])
    $response->end($redis_value);
});
$http->start();